<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

require_once 'AIR2_CRUD_Controller.php';

/**
 * Saved Search Controller
 *
 * @package default
 */
class SavedSearch_Controller extends AIR2_CRUD_Controller {

    public $base_model_name = 'SavedSearch';
    public $base_view_name  = 'savedsearch';
    public $exposed_relations = array();
    public $autoload_relations = array();
    public $column_blacklist = array();
    public $column_whitelist = array();
    public $taggable = true;
    public $unique_name_col = 'ssearch_name';

    /**
     * override single GET request to redirect if it is an HTML request
     *
     * @param unknown $uuid
     * @return unknown
     */
    public function crud_GET_one($uuid) {

        if ($this->response_view == "html") {
            $this->base_uuid = $uuid;
            $q = $this->build_query($uuid);
            $data = $this->fetch_data($q);

            // redirect
            $ssearch = json_decode($data['radix']['ssearch_params']);
            $uri = $this->uri_for('search/' . $ssearch->idx . '?' . $ssearch->params);
            redirect($uri);

            exit(0);
        }

        return parent::crud_GET_one($uuid);
    }



    /**
     * Override since we do not have an HTML view.
     */
    public function crud_GET_list() {
        if ($this->response_view == "html") {
            show_404();
            return;
        }
        parent::crud_GET_list();
    }


}
